---
title: "Local Authority RUC"
output:
flexdashboard::flex_dashboard:
orientation: columns
vertical_layout: fill
source_code: embed
---
```{r setup, include=FALSE}
library(flexdashboard)
# Data Tidying
library(tidyverse)
library(readr)
library(janitor)
# Working with Spatial Data
library(sf)
library(rmapshaper)
# Embedding HTML Widgets
library(htmltools)
library(DT)
library(leaflet)
```
```{r data-tidying, include = F}
# Import LA .shp file and LA ruc
LA_shp <- st_read("Data/Local_Authority_Districts_(December_2011)_Boundaries_EW_BFC.shp") %>%
rmapshaper::ms_simplify()
LA_ruc <- read_csv("Data/RUC_LAD_2011_EN_LU.csv") %>%
clean_names() %>%
select(lad11cd, ruc11, broad_ruc11) %>%
mutate(ruc11 = factor(ruc11, levels = c("Mainly Rural (rural including hub towns >=80%)",
"Largely Rural (rural including hub towns 50-79%)",
"Urban with Significant Rural (rural including hub towns 26-49%)",
"Urban with City and Town",
"Urban with Minor Conurbation",
"Urban with Major Conurbation")),
broad_ruc11 = factor(broad_ruc11, levels = c("Predominantly Rural",
"Urban with Significant Rural",
"Predominantly Urban")))
LA_ruc_shp <- left_join(LA_shp, LA_ruc, by = "lad11cd") %>%
st_transform(4326) # Convert from a UK Projection (epsg = 27700) to a Global Projection (epsg = 4326)
```
Column {data-width=500}
-----------------------------------------------------------------------
### Map of Local Authorities in England, by 2011 Rural Classification
```{r leaflet-plot}
# plot leaflet choropleth
palette <- c("#003300", "#00FF00", "#CCCCCC", "#00CCFF", "#3366FF", "#0000FF")
factpal <- colorFactor(palette, LA_ruc_shp$ruc11)
labels <- sprintf(
"%s
%s",
LA_ruc_shp$lad11nm, LA_ruc_shp$ruc11
) %>% lapply(htmltools::HTML)
LA_ruc_shp %>%
leaflet() %>%
addTiles() %>%
addPolygons(
stroke = T,
smoothFactor = 1,
fillOpacity = 0.7,
fillColor = ~factpal(ruc11),
color = "white",
weight = 2,
dashArray = "1",
highlight = highlightOptions(
weight = 5,
color = "#666",
dashArray = "",
fillOpacity = 0.7,
bringToFront = TRUE),
label = labels,
labelOptions = labelOptions(
style = list("font-weight" = "normal", padding = "3px 8px"),
textsize = "15px",
direction = "auto"))
```
Column {data-width=500}
-----------------------------------------------------------------------
### 2011 Local Authorities
```{r}
LA_ruc_shp %>%
st_drop_geometry() %>%
mutate(st_areasha = scales::comma(st_areasha / 1000000, accuracy = 1)) %>%
select(lad11cd, lad11nm, ruc11, broad_ruc11, st_areasha) %>%
DT::datatable(colnames = c("LA Code 2011", "LA Name", "Rural Classification (RUC)", "Broad RUC", "Area (km^2)"),
rownames = F,
options = list(scrollY="70vh", pageLength = 10))
```